﻿function changeDisplay( id )
{
  document.getElementById( id ).style.display = (document.getElementById( id ).style.display == "" ? "none" : "" );
  return false;
}

function changeSource( id, source )
{
  var element = document.getElementById( id );
  element.src = source;
}

function getRSS() 
{
  $( '#twitter_content' ).empty();

  $.get( url + 'rss/', function( data ) {  
    
    $( '#twitter_indicator' ).hide();

    maximum = 10;
    current = 0;
    
    twitter_replace = new RegExp( twitter + ": ", "gi" );

    $( data ).find( 'item' ).each( function() {   

      if ( current > maximum ) return;
      
      var tweet = $( this ).find( 'description' ).text()      
        .replace( twitter_replace , '' )
        .replace( /(http\S+)/gi   , '<a href="$1" target="_blank">$1</a>' )
        .replace( /(@)([^: ]+)/gi , '<a href="http://twitter.com/$2" target="_blank">$1$2</a>' )
        .replace( /(#)([^: ]+)/gi , '<a href="http://twitter.com/search?q=%23$2" target="_blank">$1$2</a>' );      
      
      tweet = '<p>' + tweet + '</p>';

      $( '#twitter_content' ).prepend( $(tweet) );
        
      current++;
      
    });
    
  });
}

$( document ).ready( function() {
  $( '#twitter_indicator' ).show();
  getRSS();
})